import ajax from './ajax.js'
import EventBus from './event.js'
import store from '../store'
const $bus = new EventBus()
export default {
	ajax,
	$bus,
	changeLang1(lang){
		this.$i18n.locale = lang;
	   	uni.setStorageSync('lang', this.$i18n.locale)
	},
	back(delta=1){
		uni.navigateBack({ delta:1,})
	},
	toPage(url){
		if(url.indexOf("?")>0){
			var arg = url.split("?")[1]
			var arr = arg.split("=")
			uni.setStorageSync(arr[0],arr[1])
		}
		uni.navigateTo({ url })
	},
	tip(title){
		uni.showToast({title,icon:'none',duration: 2000});
	},
	isPwd(pwd){
		return /^(?=.*)[a-zA-Z0-9]{8,20}$/.test(pwd)
	},
	render(key){
		 var { mode,type } = store.state.publishInfo; // mode =1 出售 type =1 高层
		 switch (key) {
		   case 'dipi': return mode == 1;  
		   case 'menpai-more': return /1|2|5/.test(type); //  高层 公寓 写字楼显示门牌更多信息
		   // 面积  
		   case 'area-gaocen': return /1|2/.test(type); //高层 公寓
		   case 'area-hose': return /3|4/.test(type); //别墅单家 
		   case 'area-office': return /5/.test(type); //写字楼
		   case 'area-shop': return /6/.test(type);  //商铺
		   case 'area-dipi': return mode == 1 && type == 7; // 出售地皮时候显示这个 
		   // 特色
		   case 'feature-gaocen': return /1|2/.test(type);
		   case 'feature-hose': return /3|4/.test(type);  
		   case 'feature-office': return /5/.test(type);  
		   case 'feature-shop': return /6/.test(type); 
		   // 价格
		   case 'price-sell-gaocen': return mode == 1 && /1|2/.test(type);
		   case 'price-sell-hose': return mode == 1 && /3|4/.test(type);  
		   case 'price-sell-office': return mode == 1 && /5/.test(type);  
		   case 'price-sell-shop': return mode == 1 && /6/.test(type); 
		   case 'price-dipi':return mode == 1 && type == 7;
		   
			case 'price-rent-gaocen': return mode == 2 && /1|2/.test(type);
			case 'price-rent-hose': return mode == 2 && /3|4/.test(type);  
			case 'price-rent-office': return mode == 2 && /5/.test(type);  
			case 'price-rent-shop': return mode == 2 && /6/.test(type); 
			
		   // 照片
		   case 'picture-gaocen': return /1|2/.test(type);
		   case 'picture-hose': return /3|4/.test(type);  
		   case 'picture-office': return /5/.test(type);  
		   case 'picture-shop': return /6/.test(type); 
		   case 'picture-dipi':return mode == 1 && type == 7; 
		   
		   // 状态
		   case 'state': return /1/.test(mode);
		   /********************* 物业详情中控制显示的方式 type  ******************/
		   
		   case 'detail-gaocen': return /1|2/.test(type);
		   case 'detail-hose': return /3|4/.test(type);  
		   case 'detail-office': return /5/.test(type);  
		   case 'detail-shop': return /6/.test(type); 
		   case 'detail-dipi':return mode == 1 && type == 7; 
		   
		   default:  return true;
		}

	},
	mainImg(type,item){ // propertyType,
         switch(type){
			case 6: return item.landUrl;
			case 5: return item.shopUrl;
			case 4: return item.officeBuildingUrl;
			default: return item.parlorUrl;
		 }
	}, 
}